﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MongoDB.Bson;

namespace asMeishi.web.Classes
{

    public static class functionExt
    {
        /// <summary>
        /// 转化为Mongo的ObjectId
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static ObjectId toOId(this String str)
        {
            return ObjectId.Parse(str);
        }
        public static Boolean isInputValid(this String str)
        {
            if (string.IsNullOrWhiteSpace(str)) { return false; }
            return true;
        }
        /// <summary>
        /// 产生随机数
        /// </summary>
        /// <param name="minValue">最小值</param>
        /// <param name="maxValue">最大值</param>
        /// <param name="count">产生个数</param>
        /// <returns></returns>
        public static int[] GetRandomUnrepeatArray(int minValue, int maxValue, int count)
        {

            Random rnd = new Random();
            int length = maxValue - minValue + 1;
            byte[] keys = new byte[length];
            rnd.NextBytes(keys);
            int[] items = new int[length];
            for (int i = 0; i < length; i++)
            {
                items[i] = i + minValue;
            }
            Array.Sort(keys, items);
            int[] result = new int[count];
            Array.Copy(items, result, count);
            return result;
        }

    }


}